package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.SysRegion;
import com.sc.nft.mapper.SysRegionMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

@Slf4j
@Repository
public class SysRegionDao extends ServiceImpl<SysRegionMapper, SysRegion> {


    /**
     * 通过行政编号获取对象
     * @param code
     * @return
     */
    public SysRegion administrationCode(String code) {
        LambdaQueryWrapper<SysRegion> sysRegionLambdaQueryWrapper = Wrappers.lambdaQuery();
        sysRegionLambdaQueryWrapper.eq(SysRegion::getRegionCode, code);
        sysRegionLambdaQueryWrapper.last("limit 1");
        return getOne(sysRegionLambdaQueryWrapper);
    }

    /**
     * 通过行政ID获取对象
     * @param id
     * @return SysRegion
     */
    public SysRegion administrationById(Long id) {
        LambdaQueryWrapper<SysRegion> sysRegionLambdaQueryWrapper = Wrappers.lambdaQuery();
        sysRegionLambdaQueryWrapper.eq(SysRegion::getRegionId, id);
        sysRegionLambdaQueryWrapper.last("limit 1");
        return getOne(sysRegionLambdaQueryWrapper);
    }
}
